import BaseTable from "./BaseTable"
import Pagination from "./Pagination"
import PaginationCaller from "./PaginationCaller"

/**
 * 带分页功能的表格
 * @page 页码
 * @pageSize 每页条数
 * @totalCount 总条数
 * @pageChange 翻页变更回调
 * @sizeChange 每页条数变更回调
 */
export default abstract class PaginationTable<T> extends BaseTable<T> implements Pagination {
    private __pagination_opts?: PaginationCaller
    __is_pagination = true
    page = 1
    pageSize = 10
    totalCount = 0
    constructor(opts?: PaginationCaller) {
        super();
        this.__pagination_opts = opts
    }

    pageChange = (val: number) => {
        this.page = val
        this.__pagination_opts?.pageChange(val)
    }

    sizeChange = (val: number) => {
        this.page = 1
        this.pageSize = val
        this.__pagination_opts?.sizeChange(val)
    }
}